<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // Map手写思路
      Array.prototype.myMap = function (callback) {
        let newArr = [];
        for (let i = 0; i < this.length; i++) {
          newArr.push(callback(this[i], i, this));
        }
        return newArr;
      };

      const arr = [1, 2, 3];
      arr.myMap((item, index, array) => {
        console.log(item + 1);
        console.log(index);
        console.log(array);
      });
      //filter手写思路
      Array.prototype.myFilter = function (callback) {
        let newArr = [];
        for (let i = 0; i < this.length; i++) {
          if (callback(this[i], i, this)) {
            newArr.push(this[i]);
          }
        }
        return newArr;
      };
      console.log('---------------------------------------------');
      console.log(
        arr.myFilter((item, index, array) => {
          console.log(item);
          console.log(index);
          console.log(array);
          return item > 1;
        })
      );
    </script>
  </body>
</html>
